//
//  ToolspViewController.m
//  UEAssistant
//
//  Created by mac on 2017/7/24.
//  Copyright © 2017年 youyixinxi. All rights reserved.
//

#import "ToolspViewController.h"
#import "ToolspTableViewCell.h"
#import "TeamMemoryViewController.h"
#import "ShareMemoryViewController.h"
#import "JargonViewController.h"
#import "SupToolsViewController.h"
#import <VTMagic.h>
@interface ToolspViewController ()<UITableViewDataSource,UITableViewDelegate>{

    NSArray         *_imageArr;
    NSArray         *_titleArr;
}

@property (nonatomic, strong) UITableView           *tableView;

@end

@implementation ToolspViewController

- (void)viewDidAppear:(BOOL)animated  {
    [super viewDidAppear:animated];
    self.magicController.navigationItem.rightBarButtonItem = nil;
//    self.magicController.navigationItem.leftBarButtonItem = nil;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initlizeDataSource];
    [self initlizeUserface];
}


- (void)initlizeDataSource{
    
    [self.tableView registerNib:[UINib nibWithNibName:@"ToolspTableViewCell" bundle:nil] forCellReuseIdentifier:toolsptableviewcellID];
    _titleArr = @[@"团队记忆库",@"共享记忆库",@"术语库",@"机器翻译"];
    _imageArr = @[@"团队记忆库",@"分享",@"术语库",@"辅助工具"];
}

- (void)initlizeUserface{
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tableView];
}

#pragma mark -- <UITableViewDelegate,UITableViewDataSource>

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section == 0) {
        return  3;
    }
    else{
        
        return 1;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 50*Radio;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    if (section == 0) {
        return 0.001f;
    }
    else{
        return 15*Radio;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0.001f;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if (section == 0) {
        UIView *view = nil;
        return view;
    }
    else{
        UIView *back = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 15*Radio)];
        back.backgroundColor = RGB(247, 247, 247, 1);
        return back;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    ToolspTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:toolsptableviewcellID];
    cell.titleName.font = [UIFont systemFontOfSize:FLEXIBLE(16)];
    cell.titleName.textColor = RGB(51, 51, 51, 1);
    cell.nextView.image = [UIImage imageNamed:@"更多"];
    if (indexPath.section == 0) {
        cell.titleView.image = [UIImage imageNamed:_imageArr[indexPath.row]];
        cell.titleName.text = _titleArr[indexPath.row];
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(cell.titleName.frame.origin.x, 50*Radio, Screen_Width - cell.titleName.frame.origin.x, 1)];
        line.backgroundColor = RGB(240, 240, 240, 1);
        [cell addSubview:line];
    }
    else{
        cell.titleView.image = [UIImage imageNamed:_imageArr[3]];
        cell.titleName.text = _titleArr[3];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section == 0) {
        switch (indexPath.row) {
            case 0:
            {
                self.parentViewController.hidesBottomBarWhenPushed = YES;
                TeamMemoryViewController *VC = [[TeamMemoryViewController alloc]init];
                [self.navigationController pushViewController:VC animated:YES];
            }
                break;
            case 1:
            {
                self.parentViewController.hidesBottomBarWhenPushed = YES;
                ShareMemoryViewController *VC = [[ShareMemoryViewController alloc]init];
                [self.navigationController pushViewController:VC animated:YES];

            }
                break;
            case 2:
            {
                self.parentViewController.hidesBottomBarWhenPushed = YES;
                JargonViewController *VC = [[JargonViewController alloc]init];
                [self.navigationController pushViewController:VC animated:YES];

            }
                break;
                
            default:
                break;
        }

    }else{
    
        self.parentViewController.hidesBottomBarWhenPushed = YES;
        SupToolsViewController *VC = [[SupToolsViewController alloc]init];
        [self.navigationController pushViewController:VC animated:YES];

    }
}


#pragma mark -- getter
- (UITableView *)tableView{
    
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, Screen_Height - 103) style:UITableViewStyleGrouped];
        _tableView.backgroundColor = RGB(247, 247, 247, 1);
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.separatorColor = [UIColor clearColor];
    }
    return _tableView;
}


@end
